package edu.sias.course.controller;
import edu.sias.common.core.controller.BaseController;
import edu.sias.course.domain.dto.CourseDTO;
import edu.sias.course.domain.entity.CoursePageQueryParams;
import edu.sias.course.domain.entity.PageResult;
import edu.sias.course.domain.entity.QueryPageBean;
import edu.sias.course.domain.vo.CourseAddVO;
import edu.sias.course.domain.vo.CourseAllVO;
import edu.sias.course.service.CourseService;
import edu.sias.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description CourseController
 * @Author liu
 * @Date
 */
@RestController
@RequestMapping("/course")
@Slf4j
@Api
public class CourseController  extends BaseController {

    @Resource
    private CourseService courseService;

    @ApiOperation("添加学科接口")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CourseAddVO courseAddVO){
        log.info("开始执行添加学科接口：{}",courseAddVO);
        try {
            courseService.add(courseAddVO);
            return AjaxResult.success("添加学科成功");
        } catch (Exception e) {
            log.error("添加学科异");
            return AjaxResult.error("添加学科失败，请联系管理员");
        }
    }

    @ApiOperation("学科分页列表接口")
    @PostMapping("/findListByPage.do")
    public AjaxResult findListByPage(@RequestBody QueryPageBean<CoursePageQueryParams> queryPageBean){
        log.info("开始执行学科分页列表接口：{}",queryPageBean);
        PageResult pageResult = courseService.findListByPage(queryPageBean);
        return AjaxResult.success(pageResult);
    }

    @ApiOperation("学科更新接口")
    @PostMapping("/update.do")
    public AjaxResult update(@RequestBody CourseDTO courseDTO){
        log.info("开始执行学科更新：{}",courseDTO);
        courseService.update(courseDTO);
        return AjaxResult.success("学科更新成功");
    }


    @ApiOperation("学科删除接口")
    @GetMapping("/delete.do")
    public AjaxResult delete(Integer courseId){
        log.info("开始学科删除：courseId={}"+courseId);
        courseService.delete(courseId);
        return AjaxResult.success("删除学科成功");
    }

    @ApiOperation("获取全部学科(含标签、目录列表)列表接口")
    @GetMapping("/findListAll.do")
    public AjaxResult findListAll() {
        log.info("开始获取全部学科(含标签、目录列表)列表操作...");
        List<CourseAllVO>  courseAllVO = courseService.findListAll();
        return AjaxResult.success(courseAllVO);
    }

}
